package com.isaiah.set;

import java.util.ArrayList;
import java.util.TreeSet;

/**
 * @Title: ${file_name}
 * @Description: ${todo}
 * @author: Haijun
 * @emial: isaiah@sohu.com
 * @date 2020/5/2610:09
 */
class Solution {
    public int uniqueMorseRepresentations(String[] words) {
        String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        TreeSet<String> set = new TreeSet<>();
        // 遍历每个密码字符串
        for (String word : words){
            StringBuilder res = new StringBuilder();
            // 遍历每个密码中的字符
            for (int i = 0; i < word.length(); i++){
                // 计算每个字符在的密码数组中的位置（字符-a）
                res.append(codes[word.charAt(i) - 'a']);
            }
            // 把每个字符对应的密码放入Set集合中
            set.add(res.toString());
        }
        return set.size();
    }
}